﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using CalculatorFlexibe.Interfaces;

namespace CalculatorFlexibe.Implementations
{
    class NullPOParanthesis : INullPriorityOperation
    {
        public string leftBoundary { get; set; }
        public string rightBoundary { get; set; }
        private string regExPattern;

        public NullPOParanthesis()
        {
            leftBoundary = "(";
            rightBoundary = ")";
            regExPattern = @"\({1}[^\" + leftBoundary + @"|\" + rightBoundary + @"]+\){1}";
        }

        public bool IsThereNesting(string expr)
        {
            Match match = Regex.Match(expr, regExPattern, RegexOptions.Singleline);
            return match.Value != ""; 
        }

        public string GetExpressionWithoutNesting(string expr)
        {
            Match match = Regex.Match(expr, regExPattern, RegexOptions.Singleline);
            return match.Value.Substring(leftBoundary.Length, match.Value.Length - leftBoundary.Length - rightBoundary.Length);
        }
    }
}
